package com.woniu.microassetserver.controller;

import com.github.pagehelper.PageInfo;
import com.woniu.microassetserver.service.DevTypeService;
import com.woniu.microcommonsserver.entity.DevTypeEntity;
import com.woniu.microcommonsserver.entity.ResultMsg;
import com.woniu.microcommonsserver.param.PageResult;
import com.woniu.microcommonsserver.param.ResponseMsg;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * 
 *
 * @author luoyue
 * @email 1316756108@qq.com
 * @date 2021-01-26
 */
@RestController
@RequestMapping("/devtype")
public class DevTypeController {

    @Resource
    private DevTypeService devTypeServiceImpl;


    @RequestMapping(value = "/more", produces = {"application/json;charset=utf-8"})
    public ResultMsg saveDevType() {

        System.out.println("添加");
        ResultMsg resultMsg = new ResultMsg(200, "新增成功", null);
        DevTypeEntity devTypeEntity = new DevTypeEntity(3L,"空调机",1);
        devTypeServiceImpl.saveDevType(devTypeEntity);
        System.out.println(devTypeEntity);
        System.out.println("新增成功");
        return resultMsg;
    }


    @PutMapping(value = "/id/{id}", produces = {"application/json;charset=utf-8"}) /*AssetsParameterBean assetsParameterBean, @PathVariable("id") Long id*/
    public ResultMsg updateDevType(@PathVariable("id") Long id) {
        ResultMsg resultMsg = new ResultMsg(200, "更新成功", null);
        System.out.println(id);
        DevTypeEntity devTypeEntity = new DevTypeEntity(3L,"空调机",1);
        devTypeServiceImpl.updateDevType(devTypeEntity);
        return resultMsg;
    }


    @DeleteMapping(value = "/delete/{id}", produces = {"application/json;charset=utf-8"})
    public ResultMsg deleteDevSystem(@PathVariable("id") Long id) {

        System.out.println("添加");

        ResultMsg resultMsg = new ResultMsg(200, "删除成功", null);

        devTypeServiceImpl.deleteDevType(id);

        System.out.println("删除成功");

        return  resultMsg;

    }


    @GetMapping(value = "/selectAll", produces = {"application/json;charset=utf-8"})
    public ResponseMsg selectDevType(Integer pageNum, Integer pageSize, DevTypeEntity devTypeEntity) {

        System.out.println("哦呵呵查询");


        PageInfo<DevTypeEntity> pageInfo =devTypeServiceImpl.findAllByParams(pageNum, pageSize, devTypeEntity);

        PageResult<DevTypeEntity> pageResult=new PageResult<DevTypeEntity>();
        pageResult.setRows(pageInfo.getList());
        pageResult.setTotal(pageInfo.getTotal());

        return ResponseMsg.builder().code(200).msg("查询陈工").data(pageResult).build();
    }
}
